window.lib = (function() {
  var nodeapi = '/node/msg';
  var objectMap = {};
  var searchMapDrown = false;
  var myMarker = {};
  var place_object = {};
  var coords_start = [];
  var flag = '';
  var flag2 = '';
  var refid = 0;
  
  var hideErrors = function() {
    $('.infopanel div').remove();
  }
  var showErrors = function(error, form, scroll) {
    var inf = $('.infopanel',form);
    $('div',inf).remove();
    inf.html('<div class="notice error"><ul></ul></div>');
    for (var i=0; i<error.length; i++) {
      $('ul',inf).append('<li>'+error[i]+'</li>');      
    }
    if (scroll) $(document).scrollTop(0);
  }  
  
  var showSuccess = function(success, form, scroll) {
    var inf = $('.infopanel',form);     
    $('div',inf).remove();
    inf.html('<div class="notice success"><ul></ul></div>');
    for (var i=0; i<success.length; i++) {
      $('ul',inf).append('<li>'+success[i]+'</li>');      
    }
    if (scroll) $(document).scrollTop(0);        
  }  
  
  var wopen = function(path) {
	  var nm = window.open(path,"pollwindow","toolbar=no,scrollbars=yes,directories=no,status=no,menubar=no,resizable=yes,left=0,top=0,width=500,height=200");
  	nm.focus();
  }
  
  var getParameterByName = function(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.hash);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
  }  
    
  return {
      objectMap: objectMap,
      place_object: place_object,
      coords_start: coords_start,
      flag: flag,
      flag2: flag2,
      hideErrors: hideErrors,
      showErrors: showErrors,
      showSuccess: showSuccess,
      wopen: wopen,
      nodeapi: nodeapi,
      getParameterByName: getParameterByName,
      refid: refid
  };
})(jQuery);
